﻿<cfsilent>
	<cfscript>
		
		propAdvice = getProperty("serviceFactory").getBean("termPropertyAdvice");
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		response = structNew();
		
		transaction {
			
			/* 唯一活动数据维护 */
			if ( yesNoFormat(event.getArg('status')) ) {
				sql = "SELECT
							t.term_id,t.term_prop
						FROM
							t_term t
						WHERE
							t.term_id != :term ";
				
				queryObj = new Query( datasource = application.dnsMaster ); 
				queryObj.addParam( name = "term", value = event.getArg("TID"), cfsqltype="cf_sql_char" );
				rs_otherTerm = queryObj.execute( sql=sql ).getResult();
				
				for(a = 1; a lte rs_otherTerm.recordCount; a++){
					
					propAdvice.parseProperty( rs_otherTerm['term_prop'][a] );
					
					switch ( event.getArg('prop') ) {
						
						case "Running": 
							propAdvice.setRunning(false);
							break;
						
						case "ForCourse": 
							propAdvice.setForCourse(false);
							break;
						
						case "ForExam": 
							propAdvice.setForExam(false);
							break;
						
						case "ForHalfExam": 
							propAdvice.setForHalfExam(false);
							break;
						
						case "ForChoose": 
							propAdvice.setForChoose(false);
							break;
						
						case "ForResitExam": 
							propAdvice.setForResitExam(false);
							break;

						case "ForCharge": 
							propAdvice.setForCharge(false);
							break;
					}
					
					sql = "	UPDATE 
								t_term t
							SET 
								t.term_prop = :termProp  
							WHERE 
								t.term_id = :termId ";
					
					queryObj = new Query( datasource = application.dnsMaster ); 
					queryObj.addParam( name = "termProp", value = propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name = "termId", value = rs_otherTerm['term_id'][a], cfsqltype="cf_sql_char" );
					queryObj.execute( sql = sql );
				}
				
			}
			
			/* 更新当前学期属性 */
			sql = "	SELECT
						term_prop
					FROM
						t_term
					WHERE
						term_id = :termId ";
			
			queryObj = new Query( datasource = application.dnsMaster ); 
			queryObj.addParam( name = "termId", value = event.getArg("TID"), cfsqltype="cf_sql_char" );
			rs_termEntity = queryObj.execute(sql = sql).getResult();
			
			propAdvice.parseProperty( rs_termEntity.term_prop );
			
			if ( yesNoFormat(event.getArg('status')) ) {
				
				switch ( event.getArg('prop') ) {
					
					case "Running":
						propAdvice.setRunning(true);
						break;
					
					case "ForCourse":
						propAdvice.setForCourse(true);
						break;
					
					case "ForExam":
						propAdvice.setForExam(true);
						break;
					
					case "ForHalfExam":
						propAdvice.setForHalfExam(true);
						break;
					
					case "ForChoose":
						propAdvice.setForChoose(true);
						break;
					
					case "ForResitExam":
						propAdvice.setForResitExam(true);
						break;

					case "ForCharge":
						propAdvice.setForCharge(true);
						break;
						
				}

				sql = "	UPDATE 
								t_term 
							SET 
								term_prop = :termProp  
							WHERE 
								term_id = :termId ";

				queryObj = new Query( datasource = application.dnsMaster ); 
				queryObj.addParam( name = "termProp", value = propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name = "termId", value = event.getArg("TID"), cfsqltype="cf_sql_char" );
				queryObj.execute( sql = sql );

			}
		
			structInsert(response, "Running", propAdvice.getRunning());
			structInsert(response, "ForCourse", propAdvice.getForCourse());
			structInsert(response, "ForExam", propAdvice.getForExam());
			structInsert(response, "ForHalfExam", propAdvice.getForHalfExam());
			structInsert(response, "ForChoose", propAdvice.getForChoose());
			structInsert(response, "ForResitExam", propAdvice.getForResitExam());
			structInsert(response, "ForCharge", propAdvice.getForCharge());

		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>